#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gaeo.controller import Controller

from application import models

class Rpc(Controller):
    def user_validate(self):
        field = self.params.get('field')
        value = self.params.get('value')
        
        result = {}
        if field == 'username':
            u = models.User.get_by_username(value)
            result['ok'] = u is None
            
        self.json_output(result)            
    
    def forum(self):
        try:
            method = self.params.get('method', '')
            
            if method == 'getForumInfo':
                f = models.Forum.get(self.params.get('forum_key'))
                self.json_output(json_data={
                    'ok': True,
                    'forum': {
                        'title': f.title,
                        'summary': f.summary,
                        'permalink': f.permalink
                    }
                })
            
        except:
            raise